package ec.edu.ups.cidi.siia.plamdep.frontend.utils;

import javax.faces.bean.ApplicationScoped;
import javax.inject.Named;

@Named
@ApplicationScoped
public class Html {
	
		
	String script="        <!-- The template to display files available for upload --> "+
" <script id=\"template-upload\" type=\"text/x-tmpl\"> "+
"     {% for (var i=0, file; file=o.files[i]; i++) { %} "+
" <tr class=\"template-upload fade\"> "+
"    <td class=\"preview\"><span class=\"fade\"></span></td> "+
"    <td class=\"name\"><span>{%=file.name%}</span></td> "+
"    <td class=\"size\"><span>{%=o.formatFileSize(file.size)%}</span></td> "+
"    {% if (file.error) { %} "+
"    <td class=\"error\" colspan=\"2\"><span class=\"label label-important\">Error</span> {%=file.error%}</td> "+
"    {% } else if (o.files.valid && !i) { %} "+
"    <td> "+
"        <div class=\"progress progress-success progress-striped active\" role=\"progressbar\" aria-valuemin=\"0\" aria-valuemax=\"100\" aria-valuenow=\"0\"><div class=\"bar\" style=\"width:0%;\"></div></div> "+
"    </td> "+
"    <td class=\"start\">{% if (!o.options.autoUpload) { %} "+
"        <button class=\"btn btn-primary\"> "+
"            <i class=\"icon-upload icon-white\"></i> "+
"            <span>Start</span> "+
"        </button> "+
"        {% } %}</td> "+
"    {% } else { %} "+
"    <td colspan=\"2\"></td> "+
"    {% } %} "+
"    <td class=\"cancel\">{% if (!i) { %} "+
"        <button class=\"btn btn-warning\"> "+
"            <i class=\"icon-ban-circle icon-white\"></i> "+
"            <span>Cancel</span> "+
"        </button> "+
"        {% } %}</td> "+
" </tr> "+
" {% } %} "+

" </script> "+
" <!-- The template to display files available for download --> "+
" <script id=\"template-download\" type=\"text/x-tmpl\"> "+
" {% for (var i=0, file; file=o.files[i]; i++) { %} "+
" <tr class=\"template-download fade\"> "+
" {% if (file.error) { %} "+
" <td></td> "+
" <td class=\"name\"><span>{%=file.name%}</span></td> "+
" <td class=\"size\"><span>{%=o.formatFileSize(file.size)%}</span></td> "+
" <td class=\"error\" colspan=\"2\"><span class=\"label label-important\">Error</span> {%=file.error%}</td> "+
" {% } else { %} "+
" <td class=\"preview\">{% if (file.thumbnail_url) { %} "+
" <a href=\"{%=file.url%}\" title=\"{%=file.name%}\" rel=\"gallery\" download=\"{%=file.name%}\"><img src=\"{%=file.thumbnail_url%}\"/></a> "+
" {% } %}</td> "+
" <td class=\"name\"> "+
" <a href=\"{%=file.url%}\" title=\"{%=file.name%}\" rel=\"{%=file.thumbnail_url && 'gallery'%}\" download=\"{%=file.name%}\">{%=file.name%}</a> "+
" </td> "+
" <td class=\"size\"><span>{%=o.formatFileSize(file.size)%}</span></td> "+
" <td colspan=\"2\"></td> "+
" {% } %} "+
//" <td class=\"delete\"> "+
//" <input type=\"checkbox\" name=\"delete\" value=\"1\"/> "+
//" </td> "+
" </tr> "+
" {% } %} "+
" </script> ";

	public String getScript() {
		return script;
	}

	public void setScript(String script) {
		this.script = script;
	}
	  
		/*
		
		 private static byte[] getBytesFromFile(File file) throws IOException {
		        InputStream is = new FileInputStream(file);
		        //System.out.println("\nDEBUG: FileInputStream is " + file);
		        // Get the size of the file
		        long length = file.length();
		        //System.out.println("DEBUG: Length of " + file + " is " + length + "\n");
	
		        if (length > Integer.MAX_VALUE) {
		            System.out.println("File is too large to process");
		            return null;
		        }
		        // Create the byte array to hold the data
		        byte[] bytes = new byte[(int)length];
		        // Read in the bytes
		        int offset = 0;
		        int numRead = 0;
		        while ( (offset < bytes.length)
		                &&
		                ( (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) ) {
		            offset += numRead;
		        }
		        // Ensure all the bytes have been read in
		        if (offset < bytes.length) {
		            throw new IOException("Could not completely read file " + file.getName());
		        }
		        is.close();
		        return bytes;
		    }	
		*/
}
